package com.sjh.lib_app.popup

import android.content.Intent
import android.os.Bundle
import android.os.CountDownTimer
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.sjh.lib_app.baseui.BaseActivity
import com.sjh.lib_app.R
import kotlinx.android.synthetic.main.app_activity_dialog.*

@Route(path = "/app/dialog", name = "通用弹窗页面")
class DialogActivity : BaseActivity() {

    @Autowired(desc = "这是弹窗显示的信息", required = true)
    @JvmField
    var message: String = ""

    @Autowired(desc = "这是弹窗显示的类型", required = false)
    @JvmField
    var type: Boolean = false
    val timer =object : CountDownTimer(1500, 1000) {
        override fun onFinish() {
            finish()
        }

        override fun onTick(millisUntilFinished: Long) {}
    }

    override fun onCreateRootView() = R.layout.app_activity_dialog
    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        if(intent != null){
            setIntent(intent)
            message = intent.getStringExtra("message")?:""
            type = intent.getBooleanExtra("type",false)
        }
        initViewData()
        timer.cancel()
        timer.start()
    }

    override fun onInitView(savedInstanceState: Bundle?) {
        initViewData()
        ll_dialog_parent.setOnClickListener {
            finish()
            timer.cancel()
        }
        timer.start()
    }

    private fun initViewData() {
        img_status.setImageResource(if (type) R.drawable.app_icon_hint_true else R.drawable.app_icon_hint_error)
        tv_info.setText(message)

    }

    override fun initListener() {
    }

    override fun initData() {
    }
}